'use strict';

const Sequelize = require('sequelize');
const sequelize = require('../plugins/db');
const Joi = require('@hapi/joi');
class Admin extends Sequelize.Model {}

// 静态属性：主键字段名称
Admin.pk = 'id';
Admin.init({
  username: Sequelize.STRING,
  password: Sequelize.STRING,
  salt: Sequelize.STRING,
  role: Sequelize.STRING,
  email: Sequelize.STRING,
  mobile: Sequelize.STRING,
  department: Sequelize.STRING,
  avatar: Sequelize.STRING,
  truename: Sequelize.STRING,
  area: Sequelize.STRING,
  status: Sequelize.STRING,
  creator: Sequelize.INTEGER,
  lastlogin_time: Sequelize.INTEGER
}, {
    sequelize,
    // modelName: 's_admin',
    tableName: 'admin',
    freezeTableName: true,
    timestamps: true
    // createdAt: 'create_time',
    // updatedAt: 'update_time',
})
exports.Model = Admin;
exports.Schema = Joi.object({
    username: Joi.string().required(),
    password: Joi.string().allow(null).description('密码'),
    role: Joi.string().allow(null).description('角色'),
    email: Joi.string().allow(null).description('Email'),
    mobile: Joi.string().allow(null).description('联系方式'),
    department: Joi.string().allow(null).description('部门'),
    avatar: Joi.string().allow(null).description('头像URL'),
    truename: Joi.string().allow(null).description('真实姓名'),
    area: Joi.string().allow(null).description('地区'),
    status: Joi.string().allow(null).required().description('状态')
}).label('Admin').unknown(true);